from django.db import models
from players.models import Player
from django_countries import CountryField
from django.utils.translation import ugettext_lazy as _
from hvad.models import TranslatableModel, TranslatedFields
class Category(TranslatableModel):
    tp = models.CharField(("Type of game"), help_text=_("Type of game"), max_length=1024)

    translations = TranslatedFields(
        description_tp = models.CharField(("Type of game"), help_text=_("Type of game"),max_length=1024),
    )
    def __unicode__(self):
        return self.tp

    class Meta:
        verbose_name = _("Turnament's category")
        verbose_name_plural = _("Turnament's category")

class Round(models.Model):
    first = models.ForeignKey(Player,related_name="player_first", verbose_name=_("The first player"))
    second = models.ForeignKey(Player,related_name="player_second",verbose_name=_("The second player"))
    results	= models.CharField(_('Results'), help_text=_("Results" ),max_length=1024)
    color_first	= models.CharField(_('Color of the first player'), help_text=_("Color of the first player" ),max_length=1024)
    color_second = models.CharField(_('Color of the second player'), help_text=_("Color of the second player" ),max_length=1024)
    pdn = models.CharField(_('Parties'), help_text=_("Parties" ),max_length=102400)
    number = models.IntegerField(_("Round's number"), help_text=_("Round's number"))


    def __unicode__(self):
        return "%s - %s (%s) . %s " % (self.first_player,self.second_player,self.results,self.turn.name)

    class Meta:
        verbose_name = _("Round of the turnament")
        verbose_name_plural = _("Round of the turnament")

class Turnament(models.Model):
    name = models.CharField(_('tname'), help_text=_("Turnament's name" ), max_length=1024)
    system = models.CharField(_("Turnamet's system"), help_text=_("Turnamet's system"),max_length=512)
    date_beg = models.DateField(_("Date of begining"), help_text=_("Date of begining"))
    date_end = models.DateField(_("Finish date"), help_text=_("Finish date"))
    players = models.ManyToManyField(Player, verbose_name=_("Participients of the turnament"))
    category = models.OneToOneField(Category,verbose_name=_("Category of the turnament"))
    country =  CountryField(_('Place (Country) of turnament'))
    town = models.CharField(_("Place (Town) of turnament"), help_text=_("Place (Town) of turnament"),max_length=512)
    rounds = models.ManyToManyField(Round, verbose_name=_("Rounds"))
    nround = models.IntegerField(_("Count of round"), help_text=_("Count of round"))

    def __unicode__(self):
        return self.name

    class Meta:
        verbose_name = _("Turnament's options")
        verbose_name_plural = _("Turnament's options")

class Group(models.Model):
    turnaments = models.ManyToManyField(Turnament, verbose_name=_("Group of turnament"))
    name  = models.CharField(_("Group's name"), help_text=_("Group's name" ), max_length=1024)

    def __unicode__(self):
        return self.name

    class Meta:
        verbose_name = _("Group of turnaments")
        verbose_name_plural = _("Group of turnaments")


